package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.OrderService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.client.domain.mall.Order;
import com.sun.showcase.client.query.mall.OrderQuery;

@Controller
@RequestMapping(value="/mall/order") 
public class OrderController{
	
	@Autowired
	private OrderService orderService;
	
	private Result result = new Result();
	/**
	 * 跳转到Order管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goOrder")
	public String goOrder() {
		return "mall/order";
	}
	/**
	 * 跳转到Order新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleOrder")
	public String handleOrder(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/order_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Order showDesc(OrderQuery orderQuery) {
		return orderService.get(orderQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(OrderQuery orderQuery) {
		return orderService.datagrid(orderQuery);
	}
	

	/**
	 * 添加一个Order
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(OrderQuery orderQuery) {
		orderService.add(orderQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Order
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(OrderQuery orderQuery) {
		orderService.update(orderQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Order
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(OrderQuery orderQuery) {
		orderService.delete(orderQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Order
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(OrderQuery orderQuery) {
		orderService.deletePt(orderQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Order
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(OrderQuery orderQuery) {
		List<OrderQuery> list = orderService.listAll(orderQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
	/**
	 * 全部数据Order
	 */
	@ResponseBody
	@RequestMapping(value="sendOrder")
	public Result sendOrder(OrderQuery orderQuery) {
		orderService.sendOrder(orderQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		return result;
	}
	/**
	 * 全部数据Order
	 */
	@ResponseBody
	@RequestMapping(value="homeChartData")
	public Result homeChartData(OrderQuery orderQuery) {
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(orderService.homeChartData());
		return result;
	}
	/**
	 * 全部数据Order
	 */
	@ResponseBody
	@RequestMapping(value="orderChartData")
	public Result orderChartData(OrderQuery orderQuery) {
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(orderService.orderChartData(orderQuery));
		return result;
	}
}
